<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="微信小程序AppID" prop="wechatAppid">
        <el-input
          v-model="queryParams.wechatAppid"
          placeholder="请输入微信小程序AppID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信小程序名称" prop="wechatName">
        <el-input
          v-model="queryParams.wechatName"
          placeholder="请输入微信小程序名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信小程序AppSecret" prop="wechatAppsecret">
        <el-input
          v-model="queryParams.wechatAppsecret"
          placeholder="请输入微信小程序AppSecret"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织机构ID" prop="orgId">
        <el-input
          v-model="queryParams.orgId"
          placeholder="请输入组织机构ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信商户号" prop="mchId">
        <el-input
          v-model="queryParams.mchId"
          placeholder="请输入微信商户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付API密钥" prop="payApiclientKey">
        <el-input
          v-model="queryParams.payApiclientKey"
          placeholder="请输入支付API密钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="API商户密钥" prop="apiMchKey">
        <el-input
          v-model="queryParams.apiMchKey"
          placeholder="请输入API商户密钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="APIv3密钥" prop="apiV3Key">
        <el-input
          v-model="queryParams.apiV3Key"
          placeholder="请输入APIv3密钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_common_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in dict.type.ec_audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['fun:version:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['fun:version:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['fun:version:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fun:version:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="versionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="微信小程序AppID" align="center" prop="wechatAppid" />
      <el-table-column label="微信小程序名称" align="center" prop="wechatName" />
      <el-table-column label="微信小程序AppSecret" align="center" prop="wechatAppsecret" />
      <el-table-column label="组织机构ID" align="center" prop="orgId" />
      <el-table-column label="微信商户号" align="center" prop="mchId" />
      <el-table-column label="支付API密钥" align="center" prop="payApiclientKey" />
      <el-table-column label="API商户密钥" align="center" prop="apiMchKey" />
      <el-table-column label="APIv3密钥" align="center" prop="apiV3Key" />
      <el-table-column label="密钥上传URL" align="center" prop="uploadKeyUrl" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ec_audit_status" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fun:version:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fun:version:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import { listVersion, delVersion } from "@/api/fun/version"

export default {
  name: "Version",
  dicts: ['sys_common_status', 'ec_audit_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户基本信息表格数据
      versionList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wechatAppid: null,
        wechatName: null,
        wechatAppsecret: null,
        orgId: null,
        mchId: null,
        payApiclientKey: null,
        apiMchKey: null,
        apiV3Key: null,
        uploadKeyUrl: null,
        status: null,
        auditStatus: null,
      }
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    // 监听刷新事件
    this.$eventBus.$on('refreshVersionList', () => {
      this.getList()
    })
  },
  beforeDestroy() {
    // 移除事件监听器
    this.$eventBus.$off('refreshVersionList')
  },
  methods: {
    /** 查询商户基本信息列表 */
    getList() {
      this.loading = true
      listVersion(this.queryParams).then(response => {
        this.versionList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      const query = { pageType: "add" };
      const obj = { path: "/fun/version/form", query: query };
      this.$tab.openPage("新增商户基本信息", obj.path, obj.query);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids;
      const obj = { path: "/fun/version/form", query: { pageType: "edit", id: id } };
      this.$tab.openPage("修改商户基本信息", obj.path, obj.query);
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除商户基本信息编号为"' + ids + '"的数据项？').then(function() {
        return delVersion(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fun/version/export', {
        ...this.queryParams
      }, `version_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
